<template>
  <!-- 班级信息页面 -->
  <div class="app-container">
    <el-row :gutter="20">
      <!--部门数据-->
      <el-col :span="24" :xs="24">
        <searchForm
          :formOptions="formOptions"
          @onSearch="onSearch"
          @onReset="onReset"
          :formLabelWidth="formLabelWidth"
          v-show="showSearch"
        />
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['basic:gather:add']"
              >新增</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['basic:gather:edit']"
              >修改</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['basic:gather:remove']"
              >删除</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              size="mini"
              @click="uploadBack.back = true"
              >批量上传</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              >下载导入模板</el-button
            >
          </el-col>
          <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar>
        </el-row>

        <el-table
          :data="roleList"
          @selection-change="handleSelectionChange"
          v-loading="loading"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column
            label="采集名称"
            prop="bigtName"
            align="center"
            :show-overflow-tooltip="true"
          >
          
          </el-table-column>
          <el-table-column
            label="范围名称"
            prop="bigtType"
            align="center"
            :show-overflow-tooltip="true"
          >
          <template slot-scope="scope">
              <dict-tag
                :options="dict.type.basic_collection_type"
                :value="scope.row.bigtType"
              ></dict-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="采集范围"
            prop="gradeRangeName"
            align="center"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="开始时间"
            prop="startTime"
            :show-overflow-tooltip="true"
            align="center"
          />
          <el-table-column label="结束时间" prop="endTime" align="center" />
          <el-table-column label="状态" prop="status" align="center">
            <template slot-scope="scope">
              <dict-tag
                :options="dict.type.gather_stauts"
                :value="scope.row.status"
              ></dict-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            fixed="right"
            width="160"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['basic:gather:query']"
                v-if="scope.row.status == 'A'"
                >修改</el-button
              >
              <!-- <el-button
                size="mini"
                type="text"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['basic:gather:query']"
                v-if="scope.row.status == 'A'"
                >修改</el-button
              > -->
              <el-button
                size="mini"
                type="text"
                @click="handleDelete(scope.row)"
                v-hasPermi="['basic:gather:remove']"
                >删除</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="handGather(scope.row)"
                v-hasPermi="['basic:gather:editStatus']"
                v-if="scope.row.status == 'A'"
                >开启采集</el-button
              >
              <el-button
                size="mini"
                type="text"
                @click="handOver(scope.row)"
                v-if="scope.row.status == 'B'"
                v-hasPermi="['basic:gather:editStatus']"
                >终止采集</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 添加或修改班级信息 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="60%"
      ppend-to-body
      @close="CloseIn"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="采集名称" prop="bigtName">
              <el-input
                v-model.trim="form.bigtName"
                placeholder="请输入采集名称"
                maxlength="30"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="bigtType" label="采集范围">
              <el-select
                v-model="form.bigtType"
                placeholder="请选择采集范围"
                @change="changeGrade"
                clearable
                filterable
                style="width: 100%"
              >
                <el-option
                    v-for="dict in dict.type.basic_collection_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.bigtType== '1'">
            <el-form-item label="院系" prop="gradeRange">
              <el-select
                v-model="form.gradeRange"
                clearable
                filterable
                multiple 
                placeholder="请选择"
                @change="handSpeciality"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in classTreeList"
                  :key="dict.id"
                  :label="dict.label"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.bigtType == '2'">
            <el-form-item label="院系">
              <el-select
                v-model="form.deptId"
                clearable
                filterable
                placeholder="请选择"
                @change="handSpeciality"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in classTreeList"
                  :key="dict.id"
                  :label="dict.label"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.bigtType == '2'">
            <el-form-item prop="gradeRange" label="专业">
              <el-select
                v-model="form.gradeRange"
               clearable
                filterable
                multiple 
                placeholder="请选择"
                style="width: 100%"
             
              >
                <el-option
                  v-for="dict in specialityList"
                  :key="dict.VALUE"
                  :label="dict.TITILE"
                  :value="dict.VALUE"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="gradeRange" label="年级"  v-if="form.bigtType == '3'">
              <el-select
                v-model="form.gradeRange"
                placeholder="请选择"
               clearable
                filterable
                multiple 
                class="elSelect"
                style="width: 100%"
              >
                <el-option
                  v-for="item in gradeDate"
                  :key="item.VALUE"
                  :label="item.TITILE"
                  :value="item.VALUE"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.bigtType == '4'">
            <el-form-item label="院系">
              <el-select
                v-model="form.deptId"
                clearable
                filterable
                placeholder="请选择"
                @change="handSpeciality"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in classTreeList"
                  :key="dict.id"
                  :label="dict.label"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.bigtType == '4'">
            <el-form-item label="专业" prop="specialityId">
              <el-select
                v-model="form.specialityId"
               clearable
                filterable
                placeholder="请选择"
                   @change="changeGrades"
                style="width: 100%;"
              >
                <el-option
                  v-for="dict in specialityList"
                  :key="dict.VALUE"
                  :label="dict.TITILE"
                  :value="dict.VALUE"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="gradeId" label="年级"  v-if="form.bigtType == '4'">
              <el-select
                v-model="form.gradeId"
                placeholder="请选择"
               clearable
                filterable
                  @change="changeGrades"
                class="elSelect"
                style="width: 100%;"
              >
                <el-option
                  v-for="item in gradeDate"
                  :key="item.VALUE"
                  :label="item.TITILE"
                  :value="item.VALUE"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班级" v-if="form.bigtType == '4'">
              <el-select
                v-model="form.gradeRange"
               clearable
                filterable
                multiple 
                placeholder="请选择"
                 style="width: 100%;"
              >
                <el-option
                  v-for="dict in classListType"
                  :key="dict.VALUE"
                  :label="dict.TITLE"
                  :value="dict.VALUE"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="设置时间" prop="time">
              <el-date-picker
                v-model="form.time"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @input="handleTimeChange"
                value-format="yyyy-MM-dd HH:mm:ss"
                :picker-options="pickerOptions"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <tableDate ref="formField" :initialForms="formConfig"></tableDate>
            <!-- <el-tabs
              v-model="activeName"
              @tab-click="handleClick"
              tab-position="top"
            >
              <el-tab-pane label="学生基本信息" name="userForm">
                <tableIndex ref="userForm" :tableList="classInforList" :dataList="userFormData"></tableIndex>
              </el-tab-pane>
              <el-tab-pane label="学生家庭信息" name="familyForm">
                <tableIndex ref="familyForm" :tableList="familyFormList" :dataList="familyFormData"></tableIndex>
              </el-tab-pane>
              <el-tab-pane label="学生获奖信息" name="awadForm">
                <tableIndex ref="awadForm" :tableList="awadFormList" :dataList="awadFormData"></tableIndex>
              </el-tab-pane>
            </el-tabs> -->
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="批量上传"
      :visible.sync="uploadBack.back"
      width="400px"
      append-to-body
    >
      <div style="float: left; height: 30px; line-height: 30px">上传文件：</div>
      <el-upload
        ref="uploadBacks"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="uploadBack.headers"
        :action="uploadBack.url"
        :disabled="uploadBack.isUploading"
        :on-progress="handleFileUploadBack"
        :on-success="onSuccessBack"
        :auto-upload="false"
      >
        <div class="el-upload__text">
          <i class="el-icon-upload"></i>
          <em>点击上传</em>
        </div>
        <span style="height: 30px; line-height: 30px; margin-left: 10px"
          >仅支持 xls格式文件</span
        >
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          @click="submitUploadBack"
          :disabled="submitLock"
          >确 定</el-button
        >
        <el-button @click="uploadBack.back = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="上传结果"
      :visible.sync="uploadData"
      width="500px"
      append-to-body
    >
      <div>
        共录入数据{{ studenData.totalSize }}条，上传成功{{
          studenData.successSize
        }}条，上传失败{{ studenData.errorSize }}条，下载上传结果查看。
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="importData">下载上传结果</el-button>
        <el-button @click="uploadData = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
      
      <script>
import { getDicts } from "@/api/system/dict/type";
import searchForm from "@/components/Search/searchForm.vue";
// import tableIndex from "./componets/tebleIndex.vue";
import tableDate from "./componets/tableDate.vue";
import {
  getField,
  gatherAdd,
  gatherList,
  getTather,
  delGather,
  editStatus,
  gatherEidt,
  stopStatus,
} from "@/api/flowable/gather.js";
import { getGradeSelect } from "@/api/information/gradeInfor";
import { classTree } from "@/api/information/studentInfor";
import { getClassSelect } from "@/api/information/classInfor";

import { getSpecialityByDeptId } from "@/api/information/unitMajor";


import dayjs from "dayjs";
import { getToken } from "@/utils/auth";
export default {
  name: "Role",
  dicts: ["sys_normal_disable", "basic_form_type", "gather_stauts",'basic_collection_type'],
  components: { searchForm, tableDate },
  data() {
    return {
      tableVersion: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 部门数据
      professionList: [],
      formConfig: [], // 用于存储处理后的表单配置
      // 入学年级数据
      gradeList: [],

      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      activeName: "userForm",
      formLabelWidth: "90px",
      input: "",
      formOptions: [
        {
          label: "采集名称",
          prop: "bigtName",
          element: "el-input",
          placeholder: "请输入采集名称",
        },
        {
          label: "状态",
          prop: "status",
          element: "el-select",
          options: [],
          placeholder: "请选择状态",
        },
      ],
      pickerOptions: {
        disabledDate(time) {
          // 禁止选择今天之前的日期
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      deptOptions: [],
      collegeSelectList: [],
      formsConfig: [
        { id: 1, name: "基本信息表", activeName: "userForm" },
        { id: 2, name: "家庭基本信息", activeName: "familyForm" },
        { id: 3, name: "获奖情况", activeName: "awadForm" },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        deptId: "",
        classNumber: "",
        gradeId:'',
        specialityId: '',
        gradeRange:[]
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
      formType: [],
      classInforList: [], // 基本信息字段表
      awadFormList: [], // 获奖信息字段表
      familyFormList: [], // 家庭信息字段表
      checkedCities: [], // 学生信息多选
      familyFormData: [],
      userFormData: [],
      awadFormData: [],
      gradeDate: [], // 年级信息
      classTreeList:[], // 学院信息
      specialityList: [],
      classListType:[],
      checked: false,
      // 表单校验
      rules: {
        bigtName: [
          { required: true, message: "请填写采集名称", trigger: "blur" },
        ],
        bigtType: [{ required: true, message: "请选择采集范围名称", trigger: "change" }],
        time: [{ required: true, message: "请选择时间", trigger: "change" }],
        gradeRange: [{ required: true, message: "请选择采集的范围", trigger: "change" }],
        
      },
      submitLock: false,
      uploadData: false,
      studenData: {},
      uploadBack: {
        // 是否显示弹出层（用户导入）
        back: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: true,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/basic/gather/import",
      },
    };
  },
  created() {
    //     this.getDeptTree();
    this.getList();
    getDicts("gather_stauts").then((res) => {
      this.formOptions[1].options = res.data.map((item) => {
        return {
          value: item["dictValue"],
          label: item["dictLabel"],
        };
      });
    });
  },
  methods: {
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      this.queryParams = Object.assign(this.queryParams, val);
      // console.log(arr);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // // 重置
    onReset(data) {
      console.log(data);
      this.queryParams.deptId = "";
      this.queryParams = Object.assign(this.queryParams, data);
      this.getList();
    },
    // 清除表单
    CloseIn() {
      this.form = {};
      this.open = false;
    },
    getClassList() {
      getClassSelect({
        gradeId: this.form.gradeId,
        specialtyId: this.form.specialityId,
      }).then((res) => {
        console.log(res, "班级");
        this.classListType = res.data;
      });
    },
    // 获取年级信息
    getGradeInfor() {
      getGradeSelect().then((response) => {
        // console.log(response, "Student");
        this.gradeDate = response.data;
      });
    },
    handleTimeChange(value) {
      console.log(value, "c");
      this.$nextTick(() => {
        this.$forceUpdate();
      });
    },
    changeGrades(value) {
      console.log(value, "ceeee");
      if (value != undefined) {
        if (this.form.specialityId && this.form.gradeId) {
          this.getClassList();
          this.classListType = [];
          this.form.classId = "";
        } else {
          if (!value) {
            this.classListType = [];
            this.form.classId = "";
          }
        }
      }
    },
    changeGrade(data) {
      console.log(data, "data");
        this.form.gradeRange = []
        this.form.deptId = ""
        this.changeCollege()

    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      gatherList(this.queryParams).then((response) => {
        this.roleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/basic/gather/downloadTemplate",
        {
          ...this.queryParams,
        },
        `导入模板${new Date().getTime()}.xlsx`
      );
    },
    // 查询学院
    changeCollege() {
      classTree().then((response) => {
        this.classTreeList = response.data;
      });
    },
async handSpeciality() {
  this.form.specialityId = "";
 
      this.form.classId = "";
      this.classListType = [];
      this.getSpeciality();
      // this.getGradeInfor();
    },
// async handSpeciality() {

//       this.getSpeciality();
//       // this.getGradeInfor();
//     },

    // 专业
    async getSpeciality() {
        console.log(this.form.deptId,'专业')
      if (this.form.deptId) {
        await getSpecialityByDeptId({ deptId: this.form.deptId }).then(
          (res) => {
            if (res.code == "200") {
              console.log(res,'专业')
              this.specialityList = res.data;
            } else {
              this.specialityList = [];
            }
          }
        );
      } else {
        this.specialityList = [];
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
    },
    // 安全地格式化后端时间
    formatDate(dateString) {
      return dayjs(dateString).format("YYYY-MM-DD HH:mm:ss");
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(selection);
      this.ids = selection.map((item) => item.bigtId);
      this.name = selection.map((item) => item.bigtName);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      selection.forEach((element) => {
        if (element.status == "B" || element.status == "D") {
          this.single = true;
        }
      });
    },
    handleFileUploadBack() {
      this.upload.isUploading = true;
    },
    // 上传
    submitUploadBack() {
      // 使用防抖确保只提交一次
      if (!this.submitLock) {
        this.submitLock = true;
        this.$refs.uploadBacks.submit();
        // 3秒后重置锁，防止长时间锁定
        setTimeout(() => {
          this.submitLock = false;
        }, 5000);
      }
    },
    onSuccessBack(response) {
      if (response.code == 200) {
        this.$message.success("文件上传成功");
        this.studenData = response.data;
        this.importUrl = response.url;
        this.uploadBack.isUploading = false;
        this.$refs.uploadBacks.clearFiles();
        this.uploadBack.back = false;
        this.uploadData = true;
        this.getList();
      } else {
        this.studenData = {};
        this.uploadBack.isUploading = false;
        this.$refs.uploadBacks.clearFiles();
        this.uploadBack.back = false;
        // this.uploadData = true;
        this.$message.error(response.msg);
        // this.getList();
      }
    },
    importData() {
      let link = document.createElement("a");
      //创建一个a标签
      link.style.display = "none";
      //将a标签隐藏
      link.href = process.env.VUE_APP_BASE_API + this.importUrl;
      //给a标签添加下载链接  "域名+接口"  safe是一个动态的域名  后面的接口替换成你自己的下载接口
      link.setAttribute("download", "下载上传结果");
      // 此处注意，要给a标签添加一个download属性，属性值就是文件名称 否则下载出来的文件是没有属性的，空白白
      document.body.appendChild(link);
      //将上面创建的a标签加入到body的尾部
      link.click();
      //执行a标签
    },

    /** 新增按钮操作 */
    handleAdd() {
      // this.handleClick()
      // this.$refs.formField.handleTabClick(userForm)
      this.getGradeInfor();
      this.formConfig = [
        {
          id: 1,
          name: "基本信息表",
          activeName: "userForm",
          fields: [], // 新增时为空
        },
        {
          id: 2,
          name: "家庭基本信息",
          activeName: "familyForm",
          fields: [],
        },
        {
          id: 3,
          name: "获奖情况",
          activeName: "awadForm",
          fields: [],
        },
      ];
      this.open = true;
      this.title = "设置采集信息";
    },
    /** 修改按钮操作 */
    async handleUpdate(row) {
      // this.handleClick();
      this.getGradeInfor();
      let ids = row.bigtId || this.ids;
      await getTather(ids).then((response) => {
        console.log(response, "获取详情详细");
        this.form = response.data;
        this.form.gradeRange = response.data.gradeRange.split(",");
        this.formConfig = this.processFormData(
          response.data.basicFiledSettingList
        );

        // 可选：切换到第一个表单并刷新视图
        this.$nextTick(() => {
          this.$refs.formField.switchForm(this.formConfig[0]);
        });
        // this.familyFormData = this.form.basicFiledSettingList.filter(
        // this.familyFormData = this.form.basicFiledSettingList.filter(
        //   (item) => item.formType == "familyForm"
        // );
        // this.userFormData = this.form.basicFiledSettingList.filter(
        //   (item) => item.formType == "userForm"
        // );
        // this.awadFormData = this.form.basicFiledSettingList.filter(
        //   (item) => item.formType == "awadForm"
        // );
        if (response.data.startTime && response.data.endTime) {
          this.form.time = [
            this.formatDate(response.data.startTime),
            this.formatDate(response.data.endTime),
          ];
        }

        this.open = true;
        this.title = "修改信息采集设置";
      });
    },
    processFormData(data) {
      // 1. 按 formType 分组
      const grouped = data.reduce((acc, item) => {
        const formType = item.formType;
        acc[formType] = acc[formType] || [];

        // 2. 转换字段类型（字符串转布尔值）并添加唯一标识
        acc[formType].push({
          ...item,
          columnName: item.filedName,
          comments: item.nickName,
          id: item.bfsId, // 关键：必须与子组件字段的 id 对应
          isDisplay: item.isDisplay === "Y",
          isRequired: item.isRequired === "Y",
          isModify: item.isModify === "Y",
          // 保存原始值（用于子组件重置功能）
          _original: {
            isDisplay: item.isDisplay === "Y",
            isRequired: item.isRequired === "Y",
            isModify: item.isModify === "Y",
          },
        });
        return acc;
      }, {});

      // 3. 匹配子组件的表单结构（id 和 activeName 需与子组件默认值一致）
      return [
        {
          id: 1,
          name: "基本信息表",
          activeName: "userForm",
          fields: grouped.userForm || [],
        },
        {
          id: 2,
          name: "家庭基本信息",
          activeName: "familyForm",
          fields: grouped.familyForm || [],
        },
        {
          id: 3,
          name: "获奖情况",
          activeName: "awadForm",
          fields: grouped.awadForm || [],
        },
      ];
    },
    convertBooleanToYN(array) {
      return array.map((item) => {
        const newItem = { ...item };
        for (const key in newItem) {
          if (typeof newItem[key] === "boolean") {
            newItem[key] = newItem[key] ? "Y" : "N";
          }
        }
        return newItem;
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      if (this.form.time) {
        this.form.startTime = this.form.time[0];
        this.form.endTime = this.form.time[1];
      }
      let data = this.$refs.formField.forms;
      console.log(data, "data");
      let userFormList = this.convertBooleanToYN(
        this.$refs.formField.forms[0].fields
      ).map((item) => {
        return {
          ...item,
          formType: "userForm",
        };
      });
      let familyList = this.convertBooleanToYN(
        this.$refs.formField.forms[1].fields
      ).map((item) => {
        return {
          ...item,
          formType: "familyForm",
        };
      });
      let awadFormList = this.convertBooleanToYN(
        this.$refs.formField.forms[2].fields
      ).map((item) => {
        return {
          ...item,
          formType: "awadForm",
        };
      });

      console.log(familyList, "familyList");
      // let userFormList = this.$refs.formField.selections.userForm.map((item) => {
      //   return {
      //     ...item,
      //     formType: "userForm",
      //   };
      // });
      // let awadFormList = this.$refs.formField.selections.awadForm.map((item) => {
      //   return {
      //     ...item,
      //     formType: "awadForm",
      //   };
      // });
      this.form.basicFiledSettingList = familyList.concat(
        userFormList,
        awadFormList
      );
      // // this.form.basicFiledSettingList.forEach(element => {
      // //   if(element.isDisplay == undefined){
      // //     element.isDisplay ='N'
      // //   }else if(element.isRequired == undefined) {
      // //     element.isRequired = 'N'
      // //   }else {
      // //   }
      // // });
      this.form.basicFiledSettingList = this.form.basicFiledSettingList.map(
        (item) => {
          return {
            nickName: item.comments,
            filedName: item.columnName,
            // orderNum: item.sort,
            ...item,
          };
        }
      );
      this.form.gradeRange = this.form.gradeRange.join(",");
      console.log(
        this.form,
        "提交的参数",
        awadFormList,
        userFormList,
        familyList
      );
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.bigtId != undefined) {
            gatherEidt(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.form = {};
              this.getList();
            });
          } else {
            gatherAdd(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.form = {};
            });
          }
        }
      });
    },
    // /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.bigtId || this.ids;
      this.name = row.bigtName || this.name;
      this.$modal
        .confirm('是否确认删除采集名称"' + this.name + '"的数据项？')
        .then(function () {
          return delGather(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 开启采集钮操作 */
    handGather(row) {
      const roleIds = row.bigtId;
      this.name = row.bigtName || this.name;
      this.$modal
        .confirm('是否确认开启采集名称"' + this.name + '"的数据项？')
        .then(function () {
          return editStatus(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .catch(() => {});
    },
    /** 开启采集钮操作 */
    handOver(row) {
      const roleIds = row.bigtId;
      this.name = row.bigtName || this.name;
      this.$modal
        .confirm('是否确认终止采集名称"' + this.name + '"的数据项？')
        .then(function () {
          return stopStatus(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .catch(() => {});
    },
  },
};
</script>
<style scoped>
.sort-container {
  padding: 20px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.el-upload__text {
  color: #0077fa;
  border: 1px solid #0077fa;
  background-color: #dbdcdc;
  width: 100px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  float: left;
}

/* 输入框聚焦样式 */
dev /deep/ .el-input-number.is-active {
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}

/* 表格行高亮 */
dev /deep/ .el-table__row:hover {
  background-color: #f5f7fa !important;
}

/* 排序输入框特殊样式 */
dev /deep/ .sort-input-cell .el-input-number {
  transition: all 0.3s ease;
}
</style>